#include "ServerView.h"

ServerView::ServerView(Screen *s, Model *m, LPDIRECT3DDEVICE9 dd3d): View(s, m, dd3d)
{
  _model = (ServerModel*)m;
  D3DXCreateFont(_dd3dDevice, 60, 0, FW_NORMAL, 1, false, DEFAULT_CHARSET,
                 OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH || FF_DONTCARE,
                 "Arial", &_font);
  InitRects();
}

void ServerView::InitRects(void)
{
  SetRect(&_titleRect, 100, 100, 1000, 200);
}

ServerView::~ServerView(void)
{
  _font->Release();
}

void ServerView::Draw(void)
{
  HRESULT res;
  if(background != NULL)
  {
    GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->Draw(this->background, NULL, NULL, NULL, D3DCOLOR_XRGB(255,255,255)), "NetworkMenuView::Draw background");
    _sprite->End();
    _sprite->Begin(D3DXSPRITE_ALPHABLEND);
  }

  res = _font->DrawTextA(NULL, _serverTitle, _serverTitleLen, 
                         &_titleRect,  DT_CENTER | DT_VCENTER, _serverTextColor);
}

void ServerView::HandleMessage(Message* msg)
{
  delete msg;
}

void ServerView::PreRender(void)
{
  GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->Begin(D3DXSPRITE_ALPHABLEND), "View::PreRender Sprite::Begin");
}

void ServerView::PostRender(void)
{
  GlobalDebug::GetInstance()->AssertAndLogResult(_sprite->End(), "View::PostRender Sprite::End");
}
